#include "BufferObject.h"

BufferObject::BufferObject() {
	mName = 0;
	mType = GL_ARRAY_BUFFER;
}

BufferObject::~BufferObject() {
	if (mName != 0) {
		glDeleteBuffers(1, &mName);
	}
}

GLuint BufferObject::CreateBufferObject(GLenum bufferType, GLsizeiptr size, GLenum usage, void * data) {
	mType = bufferType;
	glGenBuffers(1, &mName);
	glBindBuffer(bufferType, mName);
	glBufferData(bufferType, size, data, usage);
	glBindBuffer(bufferType, 0);
	return mName;
}

void BufferObject::UpdateData(GLenum bufferType, GLsizeiptr size, void * data){
	glBindBuffer(bufferType, mName);
	glBufferSubData(bufferType, 0, size, data);
	glBindBuffer(bufferType, 0);
}

void BufferObject::Bind() {
	glBindBuffer(mType, mName);
}

void BufferObject::Unbind() {
	glBindBuffer(mType, 0);
}
